﻿Imports System.Runtime.InteropServices
Imports System.Text

Module Win32

    <DllImport("Shlwapi.dll", CharSet:=CharSet.Auto)> _
    Public Function StrFormatByteSize(ByVal fileSize As Long, <MarshalAs(UnmanagedType.LPTStr)> ByVal buffer As StringBuilder, ByVal bufferSize As Integer) As Long
    End Function

   
    ''' <summary>
    ''' Converts a numeric value into a string that represents the number expressed as a size value in bytes, kilobytes, megabytes, or gigabytes, depending on the size.
    ''' </summary>
    ''' <param name="filesize"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function StrFormatByteSize(ByVal filesize As Long) As String
        Dim sb As New StringBuilder(11)
        StrFormatByteSize(filesize, sb, sb.Capacity)
        Return sb.ToString()
    End Function

End Module
